package bbb.sequence;

import java.util.List;
import java.util.TreeMap;

import bbb.BallInfo;
import bbb.BallMap;
import bbb.ccc.Encoder;

public class StaticAnalyze {

	public static void statistic(List<BallInfo> data) {
		int sum = 0;
		int max = 0;
		int min = Integer.MAX_VALUE;
		int count = 0;
		TreeMap<Integer,Integer> counts = new TreeMap<Integer, Integer>();
		TreeMap<Integer,Integer> cc = new TreeMap<Integer, Integer>();
		
		if (data != null && data.size() > 0) {
			for (int i = 0; i < data.size(); i++) {

				Integer bb = data.get(i).getBlue();
				Integer bc = cc.get(bb);
				if(bc == null){
					cc.put(bb, 1);
				}else{
					cc.put(bb, bc+1);
				}
				
				boolean fired = false;
				int j = 0;
				for (j = i + 1; j < data.size(); j++) {
					if (data.get(i).getBlue() == data.get(j).getBlue()) {
//						System.out.println(i+"<==>"+j+"----->"+(j-i));
						fired = true;
						break;
					}
				}
				if (fired) {
					int length = j - i;
					max = max > length ? max : length;
					min = min < length ? min : length;
					sum += length;
					count++;
					
					Integer c = counts.get(length);
					if(c == null){
						counts.put(length, 1);
					}else{
						counts.put(length, c+1);
					}
				}
			}

			System.out.println("max:" + max);
			System.out.println("min:" + min);
			System.out.println("count:" + count);
			System.out.println("avg:" + 1.0 * sum / count);
			int ddd = 0;
			for(Integer key : counts.keySet()){
				ddd += counts.get(key);
				System.out.println(key+"--"+counts.get(key)+"---" + ((0.0 + counts.get(key) )/ count)+"---" + ((0.0 + ddd )/ count));
			}
			System.out.println("======================================");
			for(Integer key : cc.keySet()){
				System.out.println(key+"--"+cc.get(key));
			}
		}

	}
	
	public static void main(String[] args){
//		BallMap.loadData();
//		List<BallInfo> balls = BallMap.data;
		List<BallInfo> balls = Encoder.randomBallList(1600);
		statistic(balls);
	}
}
